@@ -28,6 +28,8 @@ GEM |
||
28 | 28 |
addressable (2.3.6) |
29 | 29 |
arel (4.0.2) |
30 | 30 |
bcrypt (3.1.7) |
31 |
+ bootstrap-timepicker-rails (0.1.3) |
|
32 |
+ railties (>= 3.0) |
|
31 | 33 |
builder (3.1.4) |
32 | 34 |
coffee-rails (4.0.1) |
33 | 35 |
coffee-script (>= 2.2.0) |
@@ -142,6 +144,7 @@ PLATFORMS |
||
142 | 144 |
ruby |
143 | 145 |
|
144 | 146 |
DEPENDENCIES |
147 |
+ bootstrap-timepicker-rails |
|
145 | 148 |
coffee-rails (~> 4.0.0) |
146 | 149 |
devise |
147 | 150 |
flatstrap-rails |
@@ -1,5 +1,5 @@ |
||
1 | 1 |
class MissionsController < ApplicationController |
2 |
- before_action :set_mission, only: [:show, :edit, :update, :destroy] |
|
2 |
+ before_action :set_mission, only: [:show, :edit, :update, :destroy, :launch] |
|
3 | 3 |
|
4 | 4 |
before_action :authenticate_user! |
5 | 5 |
|
@@ -29,7 +29,7 @@ class MissionsController < ApplicationController |
||
29 | 29 |
# POST /missions.json |
30 | 30 |
def create |
31 | 31 |
@mission = Mission.new(mission_params) |
32 |
- |
|
32 |
+ @mission.status = 'Initializing' |
|
33 | 33 |
respond_to do |format| |
34 | 34 |
if @mission.save |
35 | 35 |
format.html { redirect_to @mission, notice: 'Mission was successfully created.' } |
@@ -54,6 +54,45 @@ class MissionsController < ApplicationController |
||
54 | 54 |
end |
55 | 55 |
end |
56 | 56 |
end |
57 |
+ |
|
58 |
+ def launch |
|
59 |
+ @mission.status = 'Launched' |
|
60 |
+ respond_to do |format| |
|
61 |
+ if @mission.save |
|
62 |
+ @users = User.all |
|
63 |
+ @mission_agents = @mission.mission_agents.all |
|
64 |
+ @users.each do |user| |
|
65 |
+ @invited = false |
|
66 |
+ @mission_agents.each do |agent| |
|
67 |
+ if agent.user != user |
|
68 |
+ agent.mission_agent_invites.each do |invite| |
|
69 |
+ if invite.user == user |
|
70 |
+ # user already invited |
|
71 |
+ @invited = true |
|
72 |
+ end |
|
73 |
+ end |
|
74 |
+ else |
|
75 |
+ @invited = true |
|
76 |
+ end |
|
77 |
+ end |
|
78 |
+ if @invited == false |
|
79 |
+ @mission_agents.each do |agent| |
|
80 |
+ if agent.user == nil |
|
81 |
+ agent.user_id = user.id |
|
82 |
+ agent.mission_agent_invites.create!(:user_id => user.id, :status => 'invited') |
|
83 |
+ agent.save |
|
84 |
+ end |
|
85 |
+ end |
|
86 |
+ end |
|
87 |
+ end |
|
88 |
+ format.html { redirect_to @mission, notice: 'Mission launched!' } |
|
89 |
+ format.json { head :no_content } |
|
90 |
+ else |
|
91 |
+ format.html { render action: 'edit' } |
|
92 |
+ format.json { render json: @mission.errors, status: :unprocessable_entity } |
|
93 |
+ end |
|
94 |
+ end |
|
95 |
+ end |
|
57 | 96 |
|
58 | 97 |
# DELETE /missions/1 |
59 | 98 |
# DELETE /missions/1.json |
@@ -3,5 +3,8 @@ class MissionAgent < ActiveRecord::Base |
||
3 | 3 |
belongs_to :user |
4 | 4 |
|
5 | 5 |
has_many :mission_agent_steps |
6 |
+ has_many :mission_agent_invites |
|
7 |
+ |
|
6 | 8 |
accepts_nested_attributes_for :mission_agent_steps, allow_destroy:true |
9 |
+ accepts_nested_attributes_for :mission_agent_invites |
|
7 | 10 |
end |
@@ -0,0 +1,4 @@ |
||
1 |
+class MissionAgentInvite < ActiveRecord::Base |
|
2 |
+ belongs_to :mission_agent |
|
3 |
+ belongs_to :user |
|
4 |
+end |
@@ -4,3 +4,4 @@ |
||
4 | 4 |
|
5 | 5 |
<%= link_to 'Show', @mission %> | |
6 | 6 |
<%= link_to 'Back', missions_path %> |
7 |
+<%= link_to 'Launch', mission_launch_path %> |
@@ -25,5 +25,24 @@ |
||
25 | 25 |
<%= @mission.agent_search_end %> |
26 | 26 |
</p> |
27 | 27 |
|
28 |
+<% @agent_number = 1 %> |
|
29 |
+<% @mission.mission_agents.each do |agent| %> |
|
30 |
+ <div class="well well-small"> |
|
31 |
+ <h3>Agent <%= @agent_number %></h3> |
|
32 |
+ <% if agent.user != nil %> |
|
33 |
+ Name: <%= agent.user.email %><br> |
|
34 |
+ Status: |
|
35 |
+ <% agent.mission_agent_invites.each do |invite| %> |
|
36 |
+ <% if invite.user = agent.user %> |
|
37 |
+ <%= invite.status %> |
|
38 |
+ <% end %> |
|
39 |
+ <% end %> |
|
40 |
+ <% else %> |
|
41 |
+ Agent not found! |
|
42 |
+ <% end %> |
|
43 |
+ </div> |
|
44 |
+ <% @agent_number = @agent_number + 1 %> |
|
45 |
+<% end %> |
|
46 |
+ |
|
28 | 47 |
<%= link_to 'Edit', edit_mission_path(@mission) %> | |
29 | 48 |
<%= link_to 'Back', missions_path %> |
@@ -3,8 +3,9 @@ AvalancheGame::Application.routes.draw do |
||
3 | 3 |
get "agent/current_missions" |
4 | 4 |
get "agent/choose_mission" |
5 | 5 |
get "agent/:id" => "agent#agent_profile" |
6 |
+ |
|
7 |
+ get "missions/:id/launch" => "missions#launch", :as => :mission_launch |
|
6 | 8 |
resources :missions |
7 |
- |
|
8 | 9 |
|
9 | 10 |
devise_for :users, :skip => [:sessions, :passwords, :confirmations, :registrations] |
10 | 11 |
as :user do |
@@ -0,0 +1,11 @@ |
||
1 |
+class CreateMissionAgentInvites < ActiveRecord::Migration |
|
2 |
+ def change |
|
3 |
+ create_table :mission_agent_invites do |t| |
|
4 |
+ t.references :user |
|
5 |
+ t.references :mission_agent |
|
6 |
+ t.string :status |
|
7 |
+ |
|
8 |
+ t.timestamps |
|
9 |
+ end |
|
10 |
+ end |
|
11 |
+end |
@@ -0,0 +1,5 @@ |
||
1 |
+class AddInviteToMissionAgent < ActiveRecord::Migration |
|
2 |
+ def change |
|
3 |
+ add_reference :mission_agents, :mission_agent_invites, index: true |
|
4 |
+ end |
|
5 |
+end |
@@ -11,7 +11,7 @@ |
||
11 | 11 |
# |
12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
13 | 13 |
|
14 |
-ActiveRecord::Schema.define(version: 20140821183452) do |
|
14 |
+ActiveRecord::Schema.define(version: 20140824233356) do |
|
15 | 15 |
|
16 | 16 |
# These are extensions that must be enabled in order to support this database |
17 | 17 |
enable_extension "plpgsql" |
@@ -29,6 +29,14 @@ ActiveRecord::Schema.define(version: 20140821183452) do |
||
29 | 29 |
add_index "friendly_id_slugs", ["sluggable_id"], name: "index_friendly_id_slugs_on_sluggable_id", using: :btree |
30 | 30 |
add_index "friendly_id_slugs", ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree |
31 | 31 |
|
32 |
+ create_table "mission_agent_invites", force: true do |t| |
|
33 |
+ t.integer "user_id" |
|
34 |
+ t.integer "mission_agent_id" |
|
35 |
+ t.string "status" |
|
36 |
+ t.datetime "created_at" |
|
37 |
+ t.datetime "updated_at" |
|
38 |
+ end |
|
39 |
+ |
|
32 | 40 |
create_table "mission_agent_steps", force: true do |t| |
33 | 41 |
t.integer "mission_agent_id" |
34 | 42 |
t.integer "step" |
@@ -52,8 +60,10 @@ ActiveRecord::Schema.define(version: 20140821183452) do |
||
52 | 60 |
t.boolean "anonymous_agent" |
53 | 61 |
t.datetime "created_at" |
54 | 62 |
t.datetime "updated_at" |
63 |
+ t.integer "mission_agent_invites_id" |
|
55 | 64 |
end |
56 | 65 |
|
66 |
+ add_index "mission_agents", ["mission_agent_invites_id"], name: "index_mission_agents_on_mission_agent_invites_id", using: :btree |
|
57 | 67 |
add_index "mission_agents", ["mission_id"], name: "index_mission_agents_on_mission_id", using: :btree |
58 | 68 |
add_index "mission_agents", ["user_id"], name: "index_mission_agents_on_user_id", using: :btree |
59 | 69 |
|
@@ -0,0 +1,9 @@ |
||
1 |
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html |
|
2 |
+ |
|
3 |
+one: |
|
4 |
+ user: |
|
5 |
+ status: MyString |
|
6 |
+ |
|
7 |
+two: |
|
8 |
+ user: |
|
9 |
+ status: MyString |
@@ -0,0 +1,7 @@ |
||
1 |
+require 'test_helper' |
|
2 |
+ |
|
3 |
+class MissionAgentInviteTest < ActiveSupport::TestCase |
|
4 |
+ # test "the truth" do |
|
5 |
+ # assert true |
|
6 |
+ # end |
|
7 |
+end |